from PyQt4 import QtCore, QtGui, uic, Qt


# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'XYZ.ui'
#
# Created: Sat Jul 23 23:48:58 2011
#      by: PyQt4 UI code generator 4.8.4
#
# WARNING! All changes made in this file will be lost!

import View.Widgets.EntityEditor.SliderWithLabels
from View.Widgets.EntityEditor.SliderWithLabels import SliderWithLabels
from View.Widgets.EntityEditor.SpinSlider import SpinSlider




class XYZ(QtGui.QGroupBox):
    def __init__(self,title="Translation",parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.spinArray = []
        self.sliderArray = []
        
        self.setTitle(title)
        self.vLayout = QVBoxLayout(self)
        
        #self.setGeometry(QtCore.QRect(9, 9, 192, 173))
        self.setObjectName("groupBox")
        #self.boxGridLayout = QtGui.QGridLayout(self)
        
        self.rangeLbl= QLabel() 
        self.rangeLbl.setText("*Range from -1000 to 1000 pixels")   
        font = QFont()
        font.setPointSize(7)
        self.rangeLbl.setFont(font) 
        #self.vLayout.addWidget(self.rangeLbl)
        
                
    def addField(self,fieldName):
        
        self.hLayout = QHBoxLayout()
        
        label = QtGui.QLabel()
        label.setText(fieldName)
        label.setMinimumWidth(30)
        
        
        self.spinSlider= SpinSlider()
        
        self.hLayout.addWidget(label)
        self.hLayout.addWidget(self.spinSlider)
        self.vLayout.addLayout(self.hLayout)
        
        '''
        self.hLayout.addWidget(label)
        self.doubleSpinBox = QtGui.QDoubleSpinBox()
        self.doubleSpinBox.setRange(-10000,10000)
       
       
        self.hLayout.addWidget(self.doubleSpinBox)

        
        self.boxGridLayout.addLayout(self.hLayout,self.spinArray.__len__(),2)
        
        '''
        '''
        
        label = QtGui.QLabel()
        label.setText(fieldName)
        
        hLayout = QtGui.QHBoxLayout()
        hLayout.addWidget(label,0)
        doubleSpinBox = QtGui.QDoubleSpinBox()
        
        
        slider = SliderWithLabels()
        slider.setObjectName(fieldName)
       
        hLayout.addWidget(doubleSpinBox)
        hLayout.addWidget(slider)
        
        
        #self.spinArray.append(doubleSpinBox)
        self.update()
        #
        '''
        '''self.slider = QSlider()
        self.slider.setOrientation(QtCore.Qt.Horizontal)
        self.slider.setMinimum(-1000.0)
        self.slider.setMaximum(1000.0)
        self.hLayout.addWidget(self.slider)
        self.spinArray.append(self.doubleSpinBox)
        
        self.sliderArray.append(self.slider)
        '''
        
        
        '''  
        print("slider = "+str(self.sliderArray.__len__())+ "/n" )
        print("slider = "+str(self.spinArray.__len__())+"/n"  )
        
        if (self.sliderArray.__len__() >0 & self.sliderArray.__len__() == self.spinArray.__len__()):
            self.idx = self.sliderArray.__len__()-1
        
            self.connect(self.sliderArray[idx], QtCore.SIGNAL('valueChanged(int)'), 
            self.changeValue)
            pass
                        
       
        #self.boxGridLayout.addLayout(self.boxGridLayout,self.spinArray.__len__(),3)
    
    def changeValue(self, value):
        self.self.sliderArray.__len__()-1.setValue(value)
        
        if value == 0:
            self.label.setPixmap(QtGui.QPixmap('mute.png'))
        elif value > 0 and value <= 30:
            self.label.setPixmap(QtGui.QPixmap('min.png'))
        elif value > 30 and value < 80:
            self.label.setPixmap(QtGui.QPixmap('med.png'))
        else:
            self.label.setPixmap(QtGui.QPixmap('max.png'))
            
        
    '''
    @QtCore.pyqtSlot()
    def on_x_valueChanged(self):
        print ("x value changed")
        
    
  
        '''
        TODO : 
        1. implémenté cette classe avec une vrai implémentation du gui!
        2. connectSlotsByName avec des nom correspendant aux titres (voir def addField())
        2. http://www.eurion.net/python-snippets/snippet/Connecting%20signals%20and%20slots.html
        
        '''


from PyQt4.Qt import *

import sys
if __name__ == "__main__":
    
    app = QApplication(sys.argv)
    
    f = XYZ("title")
    f.addField("ttest")
    f.show()
    m = QMainWindow()
    m.setCentralWidget(f)
    m.show()
    app.exec()





